<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>武钢有限组织绩效</title>
    <link href="../static/css/todostyle.css" rel="stylesheet" th:href="@{/css/todostyle.css}"/>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/css/font-awesome.min.css}"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link rel="stylesheet" th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/libs/bootstrap-treetable/bootstrap-treetable.css}"/>
    <link rel="stylesheet"
          th:href="@{/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.css}"/>
    <link rel="stylesheet" th:href="@{/css/animate.css}"/>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/libs/select/select2.css}"/>
    <link rel="stylesheet" th:href="@{/ruoyi/css/ry-ui.css}"/>
    <style>

    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form id="form-kaoping">
        <!-- <input id = "id" name="id" th:value="${approver.id}" type="hidden">-->
        <input id="roleId" name="roleId" th:value="${roleId}" type="hidden"><!-- 待办人员角色 -->
        <input id="tableId" name="tableId" th:value="${tableId}" type="hidden">
        <!-- <input id = "approveorder" name="approveorder" th:value="${approver.approveorder}" type="hidden"> -->
        <input id="projectId" name="projectId" th:value="${pefassproject.id}" type="hidden">
    </form>
    <input id="typeYB" th:value="${type}" type="hidden"/>
    <div class="container-div ui-layout-center">
        <div class="row">
            <div class="btn-group-sm" id="toolbar" role="group">

                <a id="remove" onclick="doRemoveById()"
                   th:class="${pefassproject.projectStatus!='3'}?'btn btn-danger disabled':'btn btn-danger'">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a onclick=" formBack()"
                   th:class="${pefctasstable.pStatus=='4'}?'btn btn-success disabled':'btn btn-success'">
                    <i class="fa fa-check"></i> 退回
                </a>

            </div>
            <div class="evaluate_c table2excel" id="tableDiv" style="width: 98%;">
                <table data-mobile-responsive="true" id="table"></table>
            </div>
        </div>
    </div>
</div>
<div class="radio-box" id="approverCodeDiv">

</div>
<div th:include="include::footer"></div>
<style>
    textarea.form-control {
        height: 100px;
    }
</style>
<script charset="gb2312" th:src="@{/js/rule.js}" type="text/javascript"></script>
<script type="text/javascript">
    var prefix = ctx + "zzjx/pefctasstable"
    var data = [];
    $(function () {
        doChange();
        loadMsg();


        $.modal.closeLoading();
        debugger

        $("input").bind({
            "click": function () {

                //标红输入框
                var Airport = $(this).css('background-color').toString();

                if (Airport == "rgb(255, 182, 193)") {
                    //不标红
                    $(this).css('background-color', '#FFF ');
                } else {
                    $(this).css('background-color', '#FFB6C1 ');
                }
            }

        });

    })
    /**
     * 初始化表格信息
     */

    var formulaMap = null; //公式
    var dictData = null;	//表头 rule.js需要用到这两个，一定要声明为全局变量

    function doChange() {
        var id = "";
        var tableId = $("#tableId").val(); //表单id
        var projectId = $("#projectId").val();
        if (tableId != "") {
            $.modal.loading("请等待加载预览信息!");
            $.ajax({
                url: ctx + "zzjx/pefctasstable/preview"
                ,
                data: {
                    "tableId": tableId,
                    "id": id,
                    "time": (new Date()).getTime(),
                    "pefassprojectId": projectId,
                    "type": "FJLB"
                }
                ,
                dataType: "JSON"
                ,
                type: "GET"
                ,
                async: false
                ,
                success: function (result) {
                    $.table.destroy("table");
                    dictData = result.dictData;
                    formulaMap = result.formulaMap;
                    var list = result.list;
                    buildTable($('#table'), dictData.length, list.length, dictData, list);
                    data = dictData;
                    $.modal.closeLoading();
                },
                error: function () {
                    $.modal.closeLoading();
                    $.modal.alertError("获取预览信息失败!");
                }
            })
            $("#tableDiv").removeClass("hidden");
            return false;
        }
        $("#tableDiv").addClass("hidden");
    }

    /*获取列头字段*/
    function getRows() {
        var rows = {};
        var roleId = $("#roleId").val();
        rows["id"] = guid();
        for (var dd in data) {
            var dictLabel = data[dd]["dictLabel"];//显示名称
            var dictValue = data[dd]["dictValue"];//字段值
            /*rows.push(f);*/
            rows[dictValue] = "";
        }
        return rows;
    }

    /**
     * 构建预览信息表格
     * @param $el        table对象
     * @param cells        列数
     * @param rows        行数
     * @param dictData    表头数据
     * @param list        行数据
     */
    function buildTable($el, cells, rows, dictData, list) {
        var i, j, row, columns = [], data = [];
        var isDisabled = false;
        if ($("#typeYB").val() == 1) {
            isDisabled = true;
        }
        var roleId = $("#roleId").val();
        columns.push({
            checkbox: true
        })
        columns.push({
            field: "id",
            title: "ID",
            visible: false
        })
        //拼接table,拼接表头
        for (var dd in dictData) {
            var dictLabel = dictData[dd]["dictLabel"];//显示名称
            var dictValue = dictData[dd]["dictValue"];//字段值
            var listClass = dictData[dd]["listClass"];//列显示类型(输入框，下拉框，显示)
            var isMustFill = dictData[dd]["isMustFill"];//是否为空
            var fillRoleIds = dictData[dd]["fillRoleIds"];//可评角色ID
            var f = {
                field: dictValue,
                title: dictLabel,
                sortable: false
            }
            var opt = {
                dictLabel: dictLabel,	//必填
                dictValue: dictValue,	//必填
                tableId: "table",		//必填
                ruleId: listClass,		//必填
                align: "center",
                halign: "center",
                isMustFill: isMustFill,	//必填
                isDisabled: isDisabled,
                fillRoleIds: fillRoleIds,//必填
                formId: "formTable",		//必填
            };
            f = $.rule.fmRule(opt);
            columns.push(f);
        }

        columns.push(
            {
                field: "scoringMethod",
                title: "公式ID",
                visible: false,
            }
        );

        //构建表格
        $el.bootstrapTable('destroy').bootstrapTable({
            columns: columns,
            data: list,
            uniqueId: "id",
            search: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            showExport: false,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.
            height: 600,
            pagination: false,
            modalName: "考核指标",
            onPostBody: function (data) {
                /* bding();*/
            }
        });
    }

    function doRemoveById() {
        var row = $.map($('#table').bootstrapTable('getSelections'), function (row) {
            return row;
        });
        if (row.length == 1) {

            var projectId = $("#projectId").val();
            var pefprojeindicatorId = row[0].id;
            var tableId = row[0].tableId;
            $.ajax({
                url: ctx + "zzjx/pefctasstable/toDeleteApportionData"
                , data: {"tableId": tableId, "pefprojeindicatorId": pefprojeindicatorId, "projectId": projectId}
                , dataType: "JSON"
                , type: "GET"
                , async: false
                , success: function (result) {
                    $.modal.alert(result.msg);
                    doChange();
                }, error: function () {

                    $.modal.alertError("删除失败!");
                }
            })
        } else {
            $.modal.alertWarning("请选择一条数据!");
            return false;
        }
    }


    function loadMsg() {

        var tableData = $("#table").bootstrapTable('getData');
        console.log(tableData);
        if (tableData.length > 0 && tableData instanceof Array) {
            $('#table tr').each(function (i) {                   // 遍历 tr
                $(this).children('td').each(function (j) {  // 遍历 tr 的各个 td
                    var datai = $(this).find("input[type='text']").val();
                    $(this).find("input[type='text']").prop('readonly', 'readonly');//文本框不可编辑
                    if (datai == "null") {
                        $(this).find("input[type='text']").val("");

                    }
                });
            });

        }

    }

    function formBack() {
        var tableId = $("#tableId").val(); //表单id
        var projectId = $("#projectId").val();//方案id


        //未启用顺序评分

        //的,初始化div
        $.ajax({
            url: ctx + "zzjx/pefctasstable/getApproverCodeByTableId/" + tableId,
            type: "get",
            dataType: "json",
            async: false,
            // 弹层外区域关闭
            shadeClose: true,
            success: function (result) {
                $("#approverCodeDiv").html("");
                var div = "";
                for (var i = 0; i < result.length; i++) {
                    var approverCode = result[i].approverCode;
                    var id = result[i].id;
                    div += "<div class='col-sm-6'>	<div class='form-group'><input type='checkbox' name = 'approverCode'  value='" + id + "'/> <label id='approver'>" + approverCode + "</label></div></div>";

                }
                div += "   <div class='col-sm-6'>	<div class='form-group'><span style='color: red; '>*</span>退回原因： </div></div>"
                div += "   <div class='col-sm-12'>	<div class='form-group'><textarea id='appealResult' name='appealResult' class='form-control' type='text' required height='50px'></textarea></div></div>"

                $("#approverCodeDiv").html(div);
                //打开评价人列表
                layer.open({
                    title: ['退回给', 'color:#fff;background-color:#2F4056;']
                    , skin: 'demo-class .layui-layer-title{background:#c00; color:#fff; border: none;}'
                    , type: 1
                    , area: ['400px', '300px']
                    , content: $("#approverCodeDiv")
                    // 弹层外区域关闭
                    , shadeClose: true
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //按钮【按钮一】的回调
                        //alert(1);
                        var userIds = [];//定义一个数组
                        //遍历每一个名字为approverCode的复选框，其中选中的执行函数
                        $('input[name="approverCode"]:checked').each(function () {
                            userIds.push($(this).val());//将选中的值添加到数组chk_value中
                        });
                        var userId = userIds.join(",");
                        var appealResult = $("#appealResult").val();

                        var url = ctx + "zzjx/pefctasstable/returnBackDbfj";
                        $.modal.loading("稍等");
                        $.ajax({
                            url: url,
                            type: "POST",
                            data: {
                                "tableId": tableId,
                                "projectId": projectId,
                                "userId": userId,
                                "appealResult": appealResult
                            },
                            dataType: "json",
                            async: false,
                            success: function (result) {
                                alert(result.msg);

                                $.table.search();
                                $.modal.closeLoading();
                                layer.closeAll();
                            },
                            error: function (result) {
                                $.modal.alert("操作失败，请重试!");
                                $.modal.closeLoading();
                            }
                        })
                        layer.closeAll('dialog');
                        parent.layer.close(index);//关闭弹出层
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
                        //return false 开启该代码可禁止点击该按钮关闭
                        parent.layer.close(index);//关闭弹出层
                    }
                    , cancel: function () {
                        //右上角关闭回调
                        //return false 开启该代码可禁止点击该按钮关闭
                        parent.layer.close(index);//关闭弹出层
                    }
                });
            }, error: function () {
                $.modal.alertError("系统错误");
            }
        })


    }

</script>

</body>

</html>
